1 From: Maharaja Kennadyrajan <maharaja.kennadyrajan@oss.qualcomm.com>
2 Date: Fri, 18 Jul 2025 11:38:35 +0530
3 Subject: [PATCH] wifi: mac80211: Add link iteration macro for link data
6 Currently, the existing macro for_each_link_data() uses sdata_dereference()
7 which requires the wiphy lock. This lock cannot be used in atomic or RCU
8 read-side contexts, such as in the RX path.
10 Introduce a new macro, for_each_link_data_rcu(), that iterates over link of
11 sdata using rcu_dereference(), making it safe to use in RCU contexts. This
12 allows callers to access link data without requiring the wiphy lock.
14 The macro takes into account the vif.valid_links bitmap and ensures only
15 valid links are accessed safely. Callers are responsible for ensuring that
16 rcu_read_lock() is held when using this macro.
18 Signed-off-by: Maharaja Kennadyrajan <maharaja.kennadyrajan@oss.qualcomm.com>
19 Link: https://patch.msgid.link/20250718060837.59371-3-maharaja.kennadyrajan@oss.qualcomm.com
20 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
23 --- a/net/mac80211/ieee80211_i.h
24 +++ b/net/mac80211/ieee80211_i.h
25 @@ -1237,6 +1237,19 @@ struct ieee80211_sub_if_data *vif_to_sda
26 ((__link) = sdata_dereference((__sdata)->link[__link_id], \
30 + * for_each_link_data_rcu should be used under RCU read lock.
32 +#define for_each_link_data_rcu(sdata, __link) \
33 + /* outer loop just to define the variable ... */ \
34 + for (struct ieee80211_sub_if_data *__sdata = (sdata); __sdata; \
35 + __sdata = NULL /* always stop */) \
36 + for (int __link_id = 0; \
37 + __link_id < ARRAY_SIZE((__sdata)->link); __link_id++) \
38 + if ((!(__sdata)->vif.valid_links || \
39 + (__sdata)->vif.valid_links & BIT(__link_id)) && \
40 + ((__link) = rcu_dereference((__sdata)->link[__link_id]))) \
43 ieee80211_get_mbssid_beacon_len(struct cfg80211_mbssid_elems *elems,
44 struct cfg80211_rnr_elems *rnr_elems,